package com.jmyd.commons.base.service.impl;

import com.github.pagehelper.Page;
import com.jmyd.commons.base.dto.BaseQueryDto;
import com.jmyd.commons.base.dto.KeywordQueryDto;
import com.jmyd.commons.base.dto.PageParam;
import com.jmyd.commons.base.service.IBaseService;
import com.jmyd.commons.base.vo.PageBean;
import com.jmyd.commons.constants.Constant;
import com.jmyd.commons.domain.po.SysUser;
import org.springframework.util.CollectionUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Objects;

/**
 * 公共Service接口实现类
 *
 * @param <PK> 业务主键
 * @param <D>  业务Dto
 * @param <V>  业务Vo
 * @author samphin
 * @date 2019-10-24 11:34:58
 */
public abstract class BaseServiceImpl<PK, D, V> implements IBaseService<PK, D, V> {

    @Override
    public boolean saveBatch(List<D> dto) {

        return false;
    }

    @Override
    public boolean save(D dto) {

        return false;
    }

    @Override
    public boolean save(D dto, HttpServletRequest httpServletRequest) {
        return false;
    }

    @Override
    public boolean saveSelective(D dto) {
        return false;
    }

    @Override
    public boolean saveSelective(D dto, HttpServletRequest httpServletRequest) {
        return false;
    }

    @Override
    public boolean updateById(D dto) {
        return false;
    }

    @Override
    public boolean updateById(D dto, HttpServletRequest httpServletRequest) {
        return false;
    }

    @Override
    public boolean updateByIdSelective(D dto) {
        return false;
    }

    @Override
    public boolean updateByIdSelective(D dto, HttpServletRequest httpServletRequest) {
        return false;
    }

    @Override
    public boolean deleteById(PK id) {
        return false;
    }

    @Override
    public boolean deleteBatch(List<PK> ids) {
        return false;
    }

    /**
     * 无条件查询
     */
    @Override
    public List<V> queryList() {
        return null;
    }

    /**
     * 条件查询
     *
     * @param dto
     */
    @Override
    public List<V> queryListByCondition(D dto) {

        return null;
    }

    /**
     * 条件查询
     *
     * @param dto
     */
    @Override
    public List<V> queryListByCondition(D dto, HttpServletRequest request) {

        return null;
    }

    /**
     * 分页查询
     *
     * @param queryDto
     */
    @Override
    public PageBean<V> queryPageList(BaseQueryDto<D> queryDto) {
        return null;
    }

    /**
     * 分页查询
     *
     * @param queryDto
     */
    @Override
    public PageBean<V> queryPageList(KeywordQueryDto queryDto) {
        return null;
    }

    /**
     * 分页查询
     *
     * @param queryDto
     */
    @Override
    public PageBean<V> queryPageList(PageParam queryDto) {
        return null;
    }

    /**
     * 分页查询
     *
     * @param queryDto
     */
    @Override
    public PageBean<V> queryPageList(BaseQueryDto<D> queryDto, HttpServletRequest request) {
        return null;
    }

    @Override
    public int queryCount(D dto) {
        return 0;
    }

    @Override
    public V queryById(PK id) {
        return null;
    }

    /**
     * 获取分页对象
     *
     * @author samphin
     * @date 2019-10-23 20:17:31
     */
    protected PageBean getPageData(List voList, Page page) {
        PageBean pageData = new PageBean();
        pageData.setList(voList);
        pageData.setCurrentPage(page.getPageNum());
        pageData.setPageSize(page.getPageSize());
        pageData.setTotalPage(page.getPages());
        pageData.setCount(page.getTotal());
        return pageData;
    }

    /**
     * 将Mongodb分页对象转换成系统通用分页对象
     *
     * @param pageData
     * @author samphin
     * @date 2019-11-13 09:04:12
     */
    protected PageBean getPageData(org.springframework.data.domain.Page pageData) {
        return getPageData(pageData, null);
    }

    /**
     * mongoDB分页转化
     *
     * @param pageData
     * @param dataList
     */
    protected PageBean getPageData(org.springframework.data.domain.Page pageData, List dataList) {
        PageBean pageBean = new PageBean();
        pageBean.setCount(pageData.getTotalElements());
        pageBean.setTotalPage(pageData.getTotalPages());
        pageBean.setCurrentPage(pageData.getPageable().getPageNumber());
        pageBean.setPageSize(pageData.getPageable().getPageSize());
        if (CollectionUtils.isEmpty(dataList)) {
            pageBean.setList(pageData.getContent());
        } else {
            pageBean.setList(dataList);
        }
        return pageBean;
    }

    /**
     * @param dataList
     */
    protected PageBean getPageData(int pageNum, int pageSize, long total, List dataList) {
        PageBean pageBean = new PageBean();
        pageBean.setCount(total);
        pageBean.setTotalPage((int) Math.ceil((double) total / (double) pageSize));
        pageBean.setCurrentPage(pageNum);
        pageBean.setPageSize(pageSize);
        pageBean.setList(dataList);
        return pageBean;
    }
}
